package com.coocaa.ops.admin.v1.dmp.tag.convert;


import com.coocaa.ops.admin.v1.dmp.entity.SysUserDisableTagRlsEntity;
import com.coocaa.ops.admin.v1.dmp.tag.model.DisableTagInfo;
import com.coocaa.ops.admin.v1.dmp.tag.model.TagSaveModel;
import com.coocaa.ops.common.tool.base.InstanceUtil;
import lombok.experimental.UtilityClass;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.util.Assert;

import java.util.List;

/**
 * @author bijiahao
 * @date : 2018/10/12.
 * @description
 */
@UtilityClass
public class TagSaveBeanConverter {

    public static List<SysUserDisableTagRlsEntity> getSaveDisableTagList(TagSaveModel tagSaveModel, Integer modifier) {
        List<SysUserDisableTagRlsEntity> disableTagList = InstanceUtil.newArrayList(tagSaveModel.getDisableTagInfoList().size());
        for (DisableTagInfo disableTagInfo : tagSaveModel.getDisableTagInfoList()) {
            if(CollectionUtils.isEmpty(disableTagInfo.getTagIds())){
                continue;
            }
            disableTagList.addAll(getDisableTagListForEach(tagSaveModel.getRoleId(), disableTagInfo, modifier));
        }
        return disableTagList;
    }

    private static List<SysUserDisableTagRlsEntity> getDisableTagListForEach(Integer roleId, DisableTagInfo disableTagInfo, Integer modifier) {
        List<SysUserDisableTagRlsEntity> disableTagList = InstanceUtil.newArrayList();
        Assert.notNull(disableTagInfo.getType(), "标签类型不能为空！");
        for (Integer tagId : disableTagInfo.getTagIds()) {
            disableTagList.add(getDisableTag(roleId, tagId, disableTagInfo.getType(), modifier));
        }
        return disableTagList;
    }


    private static SysUserDisableTagRlsEntity getDisableTag(Integer roleId, Integer tagId, String type, Integer modifier) {
        SysUserDisableTagRlsEntity sysUserDisableTagRlsEntity = SysUserDisableTagRlsEntity.getSysUserDisableTagRlsEntity(roleId, tagId, type);
        sysUserDisableTagRlsEntity.setModifier(modifier);
        return sysUserDisableTagRlsEntity;
    }

}
